package LeetCode;

import Util.ListNode;
import Util.SingleLinkedList;

import java.util.List;

/**
 * @author attcat
 * ---做一个有趣的程序员
 * @date 2022-10-27 22:23
 * @description
 * 输入队列  1，2，3，4  返回 4，3，2，1
 */
public class LeetCode_206 {
    public static void main(String[] args) {
        SingleLinkedList singleLinkedList=new SingleLinkedList();
        singleLinkedList.addLast(1);
        singleLinkedList.addLast(2);
        singleLinkedList.addLast(3);
        singleLinkedList.addLast(4);
        ListNode head=  singleLinkedList.getHead();
        System.out.println(singleLinkedList.toString());
        LeetCode_206 leetCode_206=new LeetCode_206();
        ListNode node= leetCode_206.reverseList(head);
        singleLinkedList.setHead(node);
        System.out.println(singleLinkedList.toString());

    }


    public ListNode  reverseList(ListNode head){
        ListNode preNode= null;
        ListNode curr=head;
        while (curr !=null){
            ListNode next=curr.next;
            curr.next=preNode;
            preNode=curr;
            curr=next;
        }
        return  preNode;
    }


}
